/**
 * @author thinking
 */
 function validMail111(login){return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(login);}
function validMail(login){return /^[_A-Za-z0-9-]+\@+[_A-Za-z0-9-\.]+$/.test(login);}
function validEmailNull(){return /[^\s]+/.test($('#email').val());}
function validAddressMail(){return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($('#email').val());}


function checkEmail(email,conPath,thisi){
$.ajax({
        url: conPath+"/user.htm?action=validEmail&email="+email.value,
        type: "post",
        timeout: 20000,
        error: function(){
            alert("Loading Error");
        },
      	  success: function(str){
        	if(str=="no"){
        		alert(thisi);
        		email.value="";
        	}
        }
    });
    return false;
}

function validateAddressNull()
{
	var form = document.forms["addShopAdd"];
	var comName=form.elements["comName"].value;
	var buyName=form.elements["buyName"].value;
	var email=form.elements["email"].value;
	var address=form.elements["address"].value;
	var city=form.elements["city"].value;
	
	var zip=form.elements["zip"].value;
	var state=form.elements["state"].value;
	var phone=form.elements["phone"].value;
	var mobile=form.elements["mobile"].value;
	
	var mobile=form.elements["mobile"].value;
	
	
	if (comName=="")
	{
		form.elements["comName"].focus();
		alert("The Company Name of address information can't be empty!");
		return false;
	}
	if (buyName=="")
	{
		form.elements["buyName"].focus();
		alert("The Contact Name of address information can't be empty!");
		return false;
	}
	if (address=="")
	{
		form.elements["address"].focus();
		alert("The Address of address information can't be empty!");
		return false;
	}
	if (city=="")
	{
		form.elements["city"].focus();
		alert("The City of address information can't be empty!");
		return false;
	}
	
	if (state=="")
	{
		form.elements["state"].focus();
		alert("The State/Province of address information can't be empty!");
		return false;
	}
	 
	 if (zip=="")
	{
		form.elements["zip"].focus();
		alert("The Postal Code of address information can't be empty!");
		return false;
	}
	 
	if (email=="")
	{
		form.elements["email"].focus();
		alert("The Email of address information can't be empty!");
		return false;
	}else{
		if(!validAddressMail()){
			 alert("Your input is not a email,please check your input!");
       		 return false;
		}
	}
	if (phone=="")
	{
		form.elements["phone"].focus();
		alert("The Phone Number of address information can't be empty!");
		return false;
	}
	
	if (mobile=="")
	{
		form.elements["mobile"].focus();
		alert("The Mobile Number of address information can't be empty!");
		return false;
	}
	
	 var flage = false;  
     var radios =form.elements["addrType"];  
  	 for (var i = 0; i < radios.length; i++) {  
         if (radios[i].checked == true) {  
            flage = true;  
          }  
     }    
	if (!flage)
	{
		alert("Please choose it is biling address or shipping address. ");
		return false;
	}
}
function checkOldPassword(obj,stri){
$.ajax({
        url: "user.htm?action=checkOldPassword&oldPassword="+obj.value,
        type: "post",
        timeout: 20000,
        error: function(){
            alert("Loading Error");
        },
      	  success: function(str){
        	if(str=="baulk"){
        		alert(stri);
        		
        		obj.value="";
        	}
        }
    });
    return false;
}
/**
 * esCart
 */
function productTotal(con,id,seId){
		$.ajax({
        url: con+"/esShipPrice.htm?action=getProductTotal&id="+id,
        type: "post",
        timeout: 20000,
        error: function(){
           
        },
      	 success: function(str){ 	
      		var totel=document.getElementById('totel'+seId);
      		totel.innerHTML=str;
      	 }
    });
    return false;
}
/**
 * esCart
 */
function quantityAjax(con,quan,seId,objValue,id,objName){
 	
 		$.ajax({
        url: con+"/esShoppingCart.htm?action=updateProduct&"+objName+"="+objValue+"&id="+id,
        type: "post",
        timeout: 20000,
        error: function(){
           
        },
      	 success: function(str){ 	
      	 var quantity=document.getElementById('productQuantity'+seId);
      	 if(str!="OUTBOUND"){
      	 	if(str!="NULL"){
      		 	if(objName=="quantity"){
      	 			var msg=document.getElementById('price'+seId);
      	 			msg.innerHTML=str;
      	 			productTotal(con,id,seId);
      		 	}
      		 }
      	 }else{
      		 if(objName=="quantity"){
      		 	alert("Trading volume can not be more than 1000 million. ");
     	 	 	quantity.value=quan;
     	 	 }
      	   }
        }
    });
    return false;
 	
}
/**
 * esCart address
 */
function validateSame()
{
	var form = document.forms["form1"];
	var billComName=form.elements["billComName"].value;
	var billBuyName=form.elements["billBuyName"].value;
	var billAddre=form.elements["billAddre"].value;
	var billCity=form.elements["billCity"].value;
	var billState=form.elements["billState"].value;
	var billCountry=form.elements["billCountry"].value;
	var billZip=form.elements["billZip"].value;
	var billPhone=form.elements["billPhone"].value;
	var billMobile=form.elements["billMobile"].value;
	var billFax=form.elements["billFax"].value;
	var billEmail=form.elements["billEmail"].value;
		
	var shipComName=form.elements["shipComName"].value;
	var shipBuyName=form.elements["shipBuyName"].value;
	var shipAddre=form.elements["shipAddre"].value;
	var shipCity=form.elements["shipCity"].value;
	var shipState=form.elements["shipState"].value;
	var shipCountry=form.elements["shipCountry"].value;
	var shipZip=form.elements["shipZip"].value;
	var shipPhone=form.elements["shipPhone"].value;
	var shipMobile=form.elements["shipMobile"].value;
	var shipFax=form.elements["shipFax"].value;
	var shipEmail=form.elements["shipEmail"].value;
	
	if (billComName=="")
	{
		form.elements["billComName"].focus();
		alert("The Company Name of billing information can't be empty!");
		return false;
	}
	if (billBuyName=="")
	{
		form.elements["billBuyName"].focus();
		alert("The Contact Name of billing information can't be empty!");
		return false;
	}
	if (billAddre=="")
	{
		form.elements["billAddre"].focus();
		alert("The Address of billing information can't be empty!");
		return false;
	}
	if (billCity=="")
	{
		form.elements["billCity"].focus();
		alert("The City of billing information can't be empty!");
		return false;
	}
	
	if (billState=="")
	{
		form.elements["billState"].focus();
		alert("The State/Province of billing information can't be empty!");
		return false;
	}
	
	
	
	if (billCountry=="")
	{
		form.elements["billCountry"].focus();
		alert("The Country of billing information can't be empty!");
		return false;
	}
	 
	 if (billZip=="")
	{
		form.elements["billZip"].focus();
		alert("The Postal Code of billing information can't be empty!");
		return false;
	}
	 
	if (billEmail=="")
	{
		form.elements["billEmail"].focus();
		alert("The Email of billing information can't be empty!");
		return false;
	}
	if (billPhone=="")
	{
		form.elements["billPhone"].focus();
		alert("The Phone Number of billing information can't be empty!");
		return false;
	}
	
	if (billMobile=="")
	{
		form.elements["billMobile"].focus();
		alert("The Mobile Number of billing information can't be empty!");
		return false;
	}
	
	
	if (shipComName=="")
	{
		form.elements["shipComName"].focus();
		alert("The Company Name of shiping information can't be empty!");
		return false;
	}
	if (shipBuyName=="")
	{
		form.elements["shipBuyName"].focus();
		alert("The Contact Name of shiping information can't be empty!");
		return false;
	}
	if (shipAddre=="")
	{
		form.elements["shipAddre"].focus();
		alert("The Address of shiping information can't be empty!");
		return false;
	}
	if (shipCity=="")
	{
		form.elements["shipCity"].focus();
		alert("The City of shiping information can't be empty!");
		return false;
	}
	
	if (shipState=="")
	{
		form.elements["shipState"].focus();
		alert("The State/Province of shiping information can't be empty!");
		return false;
	}
	
	if (shipCountry=="")
	{
		form.elements["shipCountry"].focus();
		alert("The Country of shiping information can't be empty!");
		return false;
	}
	 
	 if (shipZip=="")
	{
		form.elements["shipZip"].focus();
		alert("The Postal Code of shiping information can't be empty!");
		return false;
	}
	 
	if (shipEmail=="")
	{
		form.elements["shipEmail"].focus();
		alert("The Email of shiping information can't be empty!");
		return false;
	}
	if (shipPhone=="")
	{
		form.elements["shipPhone"].focus();
		alert("The Phone Number of shiping information can't be empty!");
		return false;
	}
	
	if (shipMobile=="")
	{
		form.elements["shipMobile"].focus();
		alert("The Mobile Number of shiping information can't be empty!");
		return false;
	}
	
	form.submit();
}
/**
 * esCart address
 */
function toTheSame()
{
	var form = document.forms["form1"];
	var checkbo=form.elements["comparecheck"];
	if (checkbo.checked)
	{
		var billComName=form.elements["billComName"].value;
		var billBuyName=form.elements["billBuyName"].value;
		var billAddre=form.elements["billAddre"].value;
		var billCity=form.elements["billCity"].value;
		var billState=form.elements["billState"].value;
		var billCountry=form.elements["billCountry"].value;
		var billZip=form.elements["billZip"].value;
		var billPhone=form.elements["billPhone"].value;
		var billMobile=form.elements["billMobile"].value;
		var billFax=form.elements["billFax"].value;
		var billEmail=form.elements["billEmail"].value;
		
		
		form.elements["shipBuyName"].value=billBuyName;
		form.elements["shipBuyName"].readOnly=true;
		
		form.elements["shipComName"].value=billComName;
		form.elements["shipComName"].readOnly=true;
		
		form.elements["shipEmail"].value=billEmail;
		form.elements["shipEmail"].readOnly=true;
		
		form.elements["shipAddre"].value=billAddre;
		form.elements["shipAddre"].readOnly=true;
		
		form.elements["shipCity"].value=billCity;
		form.elements["shipCity"].readOnly=true;
		
		form.elements["shipState"].value=billState;
		form.elements["shipState"].readOnly=true;
		
		form.elements["shipCountry"].value=billCountry;
		form.elements["shipCountry"].disabled=true;
		form.elements["sCountry"].value=billCountry;
		
		form.elements["shipZip"].value=billZip;
		form.elements["shipZip"].readOnly=true;
		
		form.elements["shipPhone"].value=billPhone;
		form.elements["shipPhone"].readOnly=true;
		
		form.elements["shipMobile"].value=billMobile;
		form.elements["shipMobile"].readOnly=true;
		
		form.elements["shipFax"].value=billFax;
		form.elements["shipFax"].readOnly=true;
		
		form.elements["shipAddress"].disabled=true;
		
		
	}
	else
	{
		form.elements["shipComName"].readOnly=false;
		
		form.elements["shipBuyName"].readOnly=false;
		
		form.elements["shipAddre"].readOnly=false;
		
		form.elements["shipState"].readOnly=false;
		
		form.elements["shipCountry"].disabled=false;
		
		form.elements["shipZip"].readOnly=false;
		
		form.elements["shipPhone"].readOnly=false;
		
		form.elements["shipMobile"].readOnly=false;
		
		form.elements["shipFax"].readOnly=false;
		
		form.elements["shipCity"].readOnly=false;	
		
		form.elements["shipEmail"].readOnly=false;		
		
		form.elements["shipAddress"].disabled=false;
	}
}
function openUrlB2b(con,addreId,sellid,target,b2bProId){
	$.ajax({
        url: con+"/user/esShopAddress.htm?action="+target+"&id="+addreId.value+"&sellerId="+sellid+"&b2bId="+b2bProId,
        type: "POST",
        dataType: "html",
        timeout: 20000,
        error: function(){
            alert("Loading Error");
        },
        success: function(html){
            $("#"+target).html(html);
        }
    });
    return false;
}

function openUrl(con,addreId,sellid,target){
$.ajax({
        url: con+"/user/esShopAddress.htm?action="+target+"&id="+addreId.value+"&sellerId="+sellid,
        type: "POST",
        dataType: "html",
        timeout: 20000,
        error: function(){
            alert("Loading Error");
        },
        success: function(html){
            $("#"+target).html(html);
        }
    });
    return false;
}
